package com.fram.controller.admin;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.fram.bean.sys.PageBean;
import com.fram.bean.sys.ResponseMsg;
import com.fram.common.canstant.ErrCode;
import com.fram.common.exception.ProException;
import com.fram.common.util.PublicMethod;
import com.fram.common.util.apiversion.ApiVersion;
import com.fram.entity.IntegralRule;
import com.fram.service.admin.IntegralRuleSerivce;

@RestController
@RequestMapping("/admin/{version}/auth/rule")
public class IntegralRuleController {
	/** 日志 **/
	private static Logger LOG = LoggerFactory.getLogger(IntegralRuleController.class);
	/****/
	@Autowired
	private IntegralRuleSerivce integralRuleSerivce;
	/**规则展示**/
	@ApiVersion(1.0)
	@RequestMapping(value = "/list",method = RequestMethod.POST)
	private ResponseMsg list(@RequestBody PageBean<IntegralRule> request) {
		ResponseMsg msg=ResponseMsg.returnBeanBuild();
		try {
			msg.setData(integralRuleSerivce.list(request));
		} catch (ProException e) {
			LOG.error("-规则->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("--规则-->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}
	/**详情**/
	@ApiVersion(1.0)
	@RequestMapping(value = "/details",method = RequestMethod.GET)
	private ResponseMsg details(Long id) {
		ResponseMsg msg=ResponseMsg.returnBeanBuild();
		try {
			msg.setData(integralRuleSerivce.details(id));
		} catch (ProException e) {
			LOG.error("-规则详情->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("--规则详情-->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}
	/****/
	@ApiVersion(1.0)
	@RequestMapping(value = "/add",method = RequestMethod.POST)
	private ResponseMsg add(@RequestBody IntegralRule request) {
		ResponseMsg msg =ResponseMsg.returnBeanBuild();
		try {
			integralRuleSerivce.add(request);
		} catch (ProException e) {
			LOG.error("-新增积分规则->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("--新增积分规则-->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}
	/**修改**/
	@ApiVersion(1.0)
	@RequestMapping(value = "/update",method = RequestMethod.POST)
	private ResponseMsg update(@RequestBody IntegralRule request) {
		ResponseMsg msg=ResponseMsg.returnBeanBuild();
		try {
			integralRuleSerivce.update(request);
		} catch (ProException e) {
			LOG.error("-新增积分规则->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("--新增积分规则-->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}
	
}
